package com.ch.tools.client.simulator.observer;

import com.ch.tools.client.simulator.controller.CharacterListViewController;
import com.ch.tools.client.simulator.observable.MapleCharactersObservable;
import javafx.application.Platform;
import javafx.collections.FXCollections;

import java.util.Observable;
import java.util.Observer;

public class MapleCharactersObserver implements Observer {

    private CharacterListViewController characterListViewController;


    public MapleCharactersObserver(CharacterListViewController characterListViewController) {
        this.characterListViewController = characterListViewController;
    }

    @Override
    public void update(Observable o, Object arg) {

        MapleCharactersObservable mapleCharactersObservable = (MapleCharactersObservable) o;

        Platform.runLater(() -> {

            characterListViewController.getMapleCharacterPacketTableView().setItems(FXCollections.observableArrayList(mapleCharactersObservable.getCharacters()));


        });
    }
}
